package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallLgBaseInfoMapper;
import org.linlinjava.litemall.db.dao.AgedmallLgMissionManRecordMapper;
import org.linlinjava.litemall.db.dao.AgedmallLgMissionMapper;
import org.linlinjava.litemall.db.domain.AgedmallLgMission;
import org.linlinjava.litemall.db.domain.AgedmallLgMissionExample;
import org.linlinjava.litemall.db.domain.AgedmallLgMissionManRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author houzb
 * 任务相关业务
 */
@Service
public class AgedmallLgMissionService {
    @Resource
    private AgedmallLgMissionManRecordMapper agedmallLgMissionManRecordMapper;
    @Resource
    private AgedmallLgMissionMapper agedmallLgMissionMapper;

    public AgedmallLgMission getMissionByBaseInfoId(Integer baseInfoId, Integer missType) {
        AgedmallLgMissionExample missionExample = new AgedmallLgMissionExample();
        missionExample.createCriteria().andBaseInfoIdEqualTo(baseInfoId).andTypeEqualTo(missType);
        List<AgedmallLgMission> missionList = agedmallLgMissionMapper.selectByExample(missionExample);
        return missionList.size() > 0 ? missionList.get(0) : null;
    }

    /**
     * 添加指定的配送人员
     * @param manId
     * @param baseInfoId
     * @param missionType 任务类型
     * @return
     */
    public int addSelLgMissionUser(long manId, long baseInfoId, int missionType) {
        AgedmallLgMissionManRecord manRecord = new AgedmallLgMissionManRecord();
        manRecord.setManId(manId);
        manRecord.setBaseInfoId(baseInfoId);
        manRecord.setMissionType(missionType);
        return agedmallLgMissionManRecordMapper.insertSelective(manRecord);
    }
}
